package com.twotwoshop.service.goods.config;




import com.twotwoshop.service.goods.interceptor.AppTokenInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器注册配置类
 */
@Configuration
@RequiredArgsConstructor
public class WebMvcConfig implements WebMvcConfigurer {

    private final StringRedisTemplate stringRedisTemplate;

    /**
     * 添加拦截器
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {


        /**
         * 全局拦截器 ----- 可以让用户不论访问哪一个界面 都会去刷新token的有效期---order=0 先执行
         */
        registry.addInterceptor(new AppTokenInterceptor(stringRedisTemplate))
                .excludePathPatterns("/**/byUserid/list/**") // 排除特定路径
                .excludePathPatterns("/**/order/**") // 排除特定路径
                .excludePathPatterns("/**/status") // 排除特定路径
                .addPathPatterns(
                        "/**"
                )
                .order(0);
    }


}
